#!/usr/bin/perl
#email_setting.cgi

require './mdmjobs-lib.pl';
&ReadParse();

&header($text{'email_detail'}, "", "index", 0, 1,undef,undef);
print "<form name=setemail action=mdm_email.cgi method=post onsubmit='return checkselect(\"$text{'err_nomember'}\",\"$text{'err_noname'}\");'>\n";
print "<table class=mode1 border=0 cellspacing=0 cellpadding=0>\n";
print "<tr><td>\n";
local $grpinfo=&foreign_call("mdmgroups","get_groupinfo");
local %grpinfo=%$grpinfo;
local @group = split (/,/,$grpinfo{'[group]'});
&select_members(\@group);	
print "</td></tr>\n";

print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<hr align=left width=550>\n";
print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<h4>$text{'index_setemail'}</h4>\n";
print "$text{'index_setemailmsg'}<p>\n";
print "</table></td></tr>\n";
print <<EOF;
<table class=mode1 width=100% border=0>
<tr><td>$text{'receiver'}:</td>
    <td><input class=text type=text size=35 name=receiver value=$receiver></td>
</tr>
<tr><td>$text{'sender'}:</td>
    <td><input class=text type=text size=35 name=sender value=$sender></td>
</tr>
<tr><td>$text{'pswd'}:</td>
    <td><input class=text type=password size=35 name=passwd value=$passwd></td>
</tr>
<tr><td>$text{'smtp'}:</td>
    <td><input class=text type=text size=35 name=smtp value=$smtp></td>
</tr>
<tr>
  <td valign=top>$text{'content_title'}:</td>
  <td>
  <p><textarea rows=5 name="content" cols=30 >$text{'content'}</textarea></p>
  </td>
</tr>
<tr><td>$text{'alert'}:</td>
    <td><input type=radio checked name=status value=disable $dis_checked >
	$text{'disable'}
        <input type=radio name=status value=enable  $en_checked  >
	$text{'enable'}
    </td>
</tr>
<tr><td>$text{'send'}:</td>
    <td><input type='checkbox' name='crit' value='yes' $crit_checked >
	$text{'crit'} 
        <input type='checkbox' name='warning' value='yes' $warning_checked >
	$text{'warning'}
        <input type='checkbox' name='info' value='yes' $info_checked >
	$text{'info'}
    </td>
</tr>
</table>

<table>
<tr>
<td>
   <input class=button1 type=submit  value=$text{'submit'}>
</td>
<td>
   <input class=button type=button  value=$text{'test'} 
    onclick='window.open("mdm_emailtest.cgi?smtp="+document.setemail.smtp.value+
"&receiver="+document.setemail.receiver.value+ 
"&sender="+document.setemail.sender.value+ 
"&passwd="+document.setemail.passwd.value+ 
"&content="+document.setemail.content.value, 
"",
"toolbar=no,menubar=no,scrollbars=yes,width=400,height=200")
'>
</td>
</tr>
</table>
EOF

print "</table></table></form>\n";
print <<EOF;
<script>
function checkselect(alertmessg1,alertmessg2)
{
	if(document.forms[0].memberlist.options.length == 0){
		alert(alertmessg1);
		return false;
	}
	
	if(!confirm("$text{'msg_confirm'}")){
                return false;
        }
	
	if(document.forms[0].listinput.value == ""){
		if(document.forms[0].memberlist.options.length > 0){
			document.forms[0].listinput.value = document.forms[0].memberlist.options[0].text;
		}else{
			document.forms[0].listinput.value = "";
		}	

		for(i = 1; i < document.forms[0].memberlist.options.length; i++){
			document.forms[0].listinput.value += "," + document.forms[0].memberlist.options[i].text;
		}
	}
}
</script>
EOF

&footer("index.cgi", $text{'index_title'});
1;
